//
//  ByRegisterCommon.m
//  oc_knowledge
//
//  Created by justiOS on 17/1/11.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCacheUser.h"

#define KEY_USER_INFO @"KEY_USER_INFO"              // 用户信息
@implementation ByCacheUser

// 存储用户信息
+ (void)setUserInfo:(ByModelUser *)userModel {
    //[ByCoreCacheSqlite3 setObjectWithKey:KEY_USER_INFO value:userModel expireTime:3600 * 24 * 30];
    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
    NSData * data =  [NSKeyedArchiver archivedDataWithRootObject:userModel];
    [userDefaults  setObject:data forKey:KEY_USER_INFO];//存储设备列表
    [userDefaults synchronize];
}
// 获取用户信息
+ (ByModelUser *)getUserInfo {
    
//    ByModelUser *user = [ByCoreCacheSqlite3 getValueWithKey:KEY_USER_INFO];
//    if (user != nil) {
//        // 更新数据库中的用户信息 修改update_time
//        [self setUserInfo:user];
//    }
    id object = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_USER_INFO];
    if (object != nil) {
        ByModelUser* user = [NSKeyedUnarchiver unarchiveObjectWithData:object];
        return user;
    }else{
        return nil;
    }

}

+ (NSArray *)getPayStyle{
    id object = [[NSUserDefaults standardUserDefaults] objectForKey:KEY_Pay_Style];
    if (object != nil) {
        return [NSKeyedUnarchiver unarchiveObjectWithData:object];
    }else{
        return [NSArray array];
    }
}

@end
